<?php

/*
 * This is to change profile photo of account.
 */
include '../../include/config.php';
$target_path = '../../storage/profile_photo/';
$fn = basename($_FILES['uploadedfile']['name']);
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if ($fn != '') {
    echo '<br>photo avail<br>';
    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
//    $fn = basename($_FILES['uploadedfile']['name']);
        $fn = 'profile_me_' . $_COOKIE['gid'] . substr($_FILES['uploadedfile']['name'], -4);
        rename($target_path,'../../storage/profile_photo/'.$fn);
        mysql_query("update salus_user_profile_detail set   photo = '" . $fn . "' where FK_fa_user_id= '" . $_COOKIE['gid'] . "'  ") or die(mysql_error());
        header('Location:../view/myaccount');
    } else {
        echo "There was an error uploading the file, please try again!";
        header('Location:../view/myaccount');
    }
} else {   
    header('Location:../view/myaccount');
}
?>
